<?php

namespace App\Console\Commands;

use App\Models\Car;
use App\Models\Category;
use App\Models\Config;
use App\Models\Notification;
use App\Models\Order;
use App\Models\User;
use App\Services\CarService;
use App\Services\PublishTemplateService;
use App\Services\SmsService;
use Illuminate\Console\Command;

class Jinchan extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'jinchan';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

        //预约通知
//        $template = new PublishTemplateService();
//        $start = date("Y-m-d",strtotime("-2 day"));
//        Car::where('status', Car::STATUS_APPOINT_ED)->where('is_exec_appoint', 0)->where('cur_date', '>=', $start)->chunk(100, function ($list) use($template){
//                foreach ($list as $car) {
//                    $user_id = $car->user_id;
//                    $user = User::find($user_id);
//                    $front_total = CarService::getFrontQueueTotal($car);
//                    if ($user && $user->weixin_openid) {
//                        $template->appoint($user->weixin_openid, $car->order_sn, $front_total);
//                    }
//                    $car->is_exec_appoint = 1;
//                    $car->save();
//                }
//            });

//        $aa = '2021-11-01 00:01:01';
//        $cur_hour =  date('H', strtotime($aa));
        \Log::info('start-jinchan');
        $cur_hour = date('H');
        if ($cur_hour >= 0 && $cur_hour <= 5) {
           // 计算昨天的进场通知
            $yesterday = date('Y-m-d', strtotime('-1 day'));
            CarService::signInNotify($yesterday);
        } else {
            $time = Config::getNotifyStartTime();
            $detail = date('Y-m-d') . $time;
            if (strtotime($detail) <=  time()) {
                CarService::signInNotify();
            }
        }


    }
}
